Some refactoring, changed Errors to use 'throw new Error();'