refctored diagnostic output to its own funciton and cosmetic changes