General sparse codes, more tests, fixes throughout.