Fixed alot of stuff that I don't remember.

Fixed mainloop for one.