A couple of bug fixes, beginning to make things more modular.