Updated callback to check for typeof function before attempting to execute.