Same function abstraction here would be great.  Would move relevant code, as well as checks, into that function.