refactored
added tests