fix several allocation bugs
fix various bugs, only JSONRecordReader test is failing