adding refactored solution