tE-22: introduced metrics gathering and minor code cleanup, initial integration for sonar