fixes to main.js to make events work correctly.