refactor finish and write methods