Bug fixed and debug messages added