Fixes error handling