Minor refactoring and fixes
Refactored tests to use expectedException
Added more tests