Directly return int instead of string
Moved averaging into own function

No need to have that in the main loop.