Defensive returning of error codes as suggested by last-g.
Tidy up.