Moved dynamic event listener to a named function. Main loads correctly now.