Not sure if this is the best way to do it, but it might work.
Closes #211 (closed), #228 (closed) and #227 (closed)