Add MIT license
Cleaned up some code

- remove use of globals
- split some files apart
- added halidator support