Improved JSON handling