Used case-of pattern matching to improve safety.

Improved debug print statements.