Fix incorrect debug output and simplified edge cases