Reworked error handling to correctly pass back error message