Another test case along with some fixes. Removed the inclusion of local
state in the function context to improve performance. Might be
reincluded given a better implementation is found...