Refactored tests to test generic errors
Refactored code for generic error handeling/throwing
Refactored duplicated code