update unit tests and a lil refactoring