Refactoring and some more tests added