Cleanup and fixes

Please feel free to reject this if you don't like some of the changes. Just tell me what needs changing, and I will incorporate it and create a new PR.