Fixed logic error.
Moved debug call into extracted function.