Added unit tests. Fixed some code, etc.