refactor rate calculation