Cleanup in main.js, DRY-ing things out.