Lots of changes

- Lots of refactoring so its easier to understand whats happening
- Can be run straight from the command line