Finished code for the most part