Various cleanups and small changes

I was looking at using your module and browsing through the code and ended up hacking a bit on things, and thought I'd send the changes upstream to you. Let me know if you have any questions about what I did, or if you want to make changes to things before pulling them. All tests still pass, and I added a few- I wasn't sure where the preferred location was given they are currently in a few different places.