Finished code for post 3