Fixed some small issues and added debug messages