refactoring common code for call backs