Replaced the old code with cleaner, easier to reason code. There is a bug in the GridModel initiation code such that its rows and columns are transposed.