finished refactoring after taking suggestions