refactors big switch statement in main.js

This makes the actions easier to test.
Maybe we could add jasmine to write some tests?