externalize debugging script, refactoring