Code cleanup

Code-cleanup branch currently matches Master in terms of functionality.
Comments are in new style.