Changed code according to the comments provided