Updating debug output to be more inline with the application flow
Rearranging the code a little bit