Added error handling for undefined callbacks