Bug fixes, and refactoring to have the code reside in the right places.