Refactored after code review