refactored for some code smells