Whitespace and code format cleanup
made never changing vars => consts
added function debug() to replace repeating if(DEBUG) statements