moved some logic around