Fixed API by making the code properly return errors