calculate mean, some other cleanup