Added function for calculating view range