Refactoring, added an initial set of tests