refactored code for cleanliness