Finished the code for the exercise