adding logic for average