Better comments, some extra error checking.