Add state change collision and clean up code

Still a lot of work to do in the clean code front! Like...
- Move classes to seperate files with ES6 module syntax
- Reduce the cyclomatic complexity
- Use less 'global' variables.. Split up the function inside my promise