(It is very conventional to use everything-is-an-expression to factor out common code like @kballard suggests.)