More explicit handling of weights.
Improved error handling, and guarded all new-operations.