Small fixes for error handling