Added logging and bug fixes.