fixed bug writing first record