adding guard around callback functions