Some refactoring to please JSHint. Use IIFEs.