maybe check it is a function, rather than if it is not undefined