Added true AMD compatibility, some code cleanup and formatting, minor optimization of jQuery selectors