Fixed logic a bit, also a bug that I'm not sure broke anything