Using class variables instead of globals.

- first pass at do_when as well.
- closes #2