fixed a memory leak, read length setting and misc.