Added test and refactored