Defined a macro to replace apply-on-rectangle. Increased speed of inner-loops.