speed up and fix bug

speed up by keeping data in memory (haven't fully tested speed)

fix off by one bug for max number of massblocks