Alice hardened the code, added more tests and checks for test cases.

Hardened code, added checks, more test cases.