Added instances parameter to functions

Where it makes sense, functions take a parameter 'instances', which
means that the function only uses these instances in evaluation /
whatever it is it is doing.