Refactored due to code review