cleanup, fix write/sync bug