Added error trapping for zero in several places.