Some refactoring and hooking into the proper Map onLoad event (rather than document ready).