Abstract this if/else into a method that accepts the options object and conditionally does the right thing.