Merge olivares's changes, and fix json handling