Rework to return errors in a better way