Fixed a bunch of logic