Calculate and invoke function