Finished code. Added final code and everything is working.