Moved some if's and else's around to fix logic