subroutine range calculations