updated code with given example