Minor refactoring and incorporating recommendations from JSHint
Adding minified version