Fixed all major bugs.

Code works perfectly. Still needs a few more things to be fixed, but
there is nothing majorly wrong with my code anymore.