add support for functions + bug fixes