Replaced range by using min and max explicitly