was not flushing buffer in write_and_flush OMG!