rewrite append file implementation