Added log messages and fixed bug.