added tests
refactored