fixed getweights() function