cleanups

Non-functional modifications so that the code reads better. Yeah I know, it's
a monster commit, should have split it up...
improve debug output