Code cleanup, comments, refactoring, minor fixes.