Require environment to require json
Use reopen instead of doing it by hand with fcntl
Misc cleanup