Refactoring

- Add JSON dependency.
- Coding style consistency (mostly).
- Refactor as much code into classes as much as possible.
- Better threading instead of relying on forever loops and sleep.