Changed 'rate' function to make it faster.

All the changes are behind the scene. It does not change the way this
function works.