Refactored and added Test