Refactored code, according to remarks from code review