Added (now disabled) debug print statements and fixed a bug or two.