Refactoring
Refactoring
Fixed average function