Added logging and minor fixes.