add support for named functions
improve error message