Refactored - added tests