Cleaned up code and fixed bugs

Here's an example of how I would clean up the code a little and fix some of the bugs