Unit tests

Further refactoring is needed