refactored method, added tests