refactored and testing