Fixed a bunch of bugs and prevented bugs