Minor code rearrangement and change of error messages.