unit test cleanup

fixed some bugs and missing API and did some cleanups

replace all occurrences of "throw" with "raise"