First pull request

* Changed the way in which JSON is parsed
* Added stage logic to the main loop