Small cleanup

This branch is mostly about removing the hand written functional equivalents of ThreadLocal.

Accidentally, it also fixes #103