refactored, tests added