added more support for sample writting