Fix bug in error routine