#21 enhanced debugging and changes to try to fix the bug