Added debugger support in debug mode, refactoring.