fixes #62

I think I've left enough comments on #62 to explain everything but I'll leave comments on anything that seems noteworthy.