Return 0 on success, 1 on failure.