Changed termination condition of recursion in BP
Order templates spatially after fitting model
Implemented greedy search as MEX file