Not sure I get why we have "3" as a return code here. Maybe just use -1 for error? Also I don't think I fully understand this.

1 is ok I guess, 3 is not ok. But what for other values? What does it mean?