made the main JSON generation loop more accurate