Moved error handling code to new method, added severity constants.