Fixed a bunch of stuff and refactored, still ugly.
But what do people expect :D