Fix bug and add debug level log.