added null checking for callbacks