Filled the code according to the comments