remove a debug statement and move some logic around