removed debug outputs and add avg()