added missing type check before calling optional callback function