fixed some bug in writer