Adding error-checking to selected functions.