Added stronger error checking when executing user supplied functions. Added more tests.