Error handling bugfix