refactored solution again