This function is the main fix for issue #710 .