Factored out weights function