Initial implementation of max-run tests, plus bug fixes.

Attached to issues #9 and #10.