Fixed a bug and added debug log messages