fix range calculation