Added debug messages and functionality