Bug fixed on calculating average