Removed a python call in a tight inner loop for substantial speed gain.