refactored, added new tests