modified code after feedback