Fixing main average algo