Refactored JSON logic (added unit-test). Fulfilling messages on poll (untested).