Updated code with reviewer's suggestions