Fixed some errors and cleaned up much!

I fixed a lot see if you can finish it off based on what i did. Also much of this should be put into a class. But i'm not sure if you have made it that far yet.