modified refactored solution