Finding rect and expand routine is updated.
Refactoring is performed also.