And there might be a more scala idiomatic way to handle the 3 code paths here. @ryanlecompte ?