General code clean up and finished adding unit tests.