Fixed a couple logic errors