Refactoring and tests for class

I had changed some of this for a personal project and thought it might be helpful to integrate some of the changes into the original.