Refactoring and added more debugging tool(s)