Remove monkey patching

This contains fixes for #7 and #8, as well as some other housekeeping/tidying up.