refactored and added test