old//new. new much much shorter and faster, also created a helper function to find a,b,c ranges