fixes #259

I caught a couple places that needed refactoring. Please let me know if you find more.