use DEBUG flag and printf macro
misc refactoring
cleanup whitespace