Switched some logoic around to make it more readable.