Added edge case testing, debug printing...

... error checking and better formatting.
Merged