Improve handling of functions