Code cleanup and debugmode
Debug mode added
Code cleanup and debugmode