factor out write methods for different usage