Various bug fixes; it's starting to work.