refactored based on solutions