Moved exception handling to the right level