Added error check for undefined functions.