refactored due to code review