pre-calculate weighted means in db, varios other improvemnts