Basic debugging and refactoring