Bug fix and add more debug log.