Code cleanups, function and var name refactoring, add comments.