Added error checking for function application back in