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