incorporate the ability to use named vector w rather than fixed order and include error handling
incorporate the ability to use named vector w rather than fixed order and include error handling