Fixed missing error checking on the last line.
Minor changes.