Added some debug messages and a minor bug fix