Reduce the number of cast, no functional change
Fix for #907
Fix for #908