Refactored weights_as_params (via @cristicbz)