Add debug option + refactoring