Improved version: removed the analyse element duplicate code and put it
in a method