Exceptionhantering refactoring.