Updated code after feedback from code review issue #740