Improved square analyser algorithm to avoid the creation of too many object