refactored answer