Cleaned up code, and added the beginnings of a unit test