Added comments and changed debug messages