strengthened handling of invalid data
improvements suggested by Robert Fairlie-Cuninghame