Changed function signatures so the weights are always the last argument