conditionally write