Code cleanup & refactoring, incl. JSHint warning fixes.