Further debug encapsulation and code clean-up