Error check extended to cover both checks. Some minor code cleanup.