Refactoring - removed much of the debug logging