refactored target.write()