adds support for custom functions

passed as a second argument