Creating new unittests and refactoring code to clean things up