More refactoring/debugging