Basic refactoring

This is the most basic refactoring, just simplified things just a bit.
I will do some more soon. Some things i think should be done :
* use promises instead of passing around callbacks
* model the UI so you can access it like an object and hide DOM selectors from the logic.