More gateway/state hacking and JSON