updated code after feedback