Implemented fix of tschettler from issue #577 rather than my fix.