modified error handling to allow zeros in a weight matrix