Previously some functions returned 1 and some returned -1 on error. There were also two internal functions that returned 0 on error and 1 on 0 on success. Fix this, and make sure we always return -1 on error and 0 on success.