speedup fixing insertions part by not doing within a pandas data frame
updating collapse by grid method to be faster