More logging, some tests, and a bugfix.