Mostly adding tests. Tracked down a few bugs related to weights.