#1 initial unit tests and bug fixes