fixed file reading and buffer conversion