fix bug in avarage, might want to find a more intelligent solution