Fix short write bug