changed logic around to make more sense when reading