Added logging facility; a few bug fixes.