Large parts of the code were written with 2-space-indents only. Upgraded to 4-space indents to improve readability. Sorry for touching almost every line. :-S