The contents of both callbacks is identical - factor out into a separate local function and call it from both branches.