a bunch of changes

I didn't figure out what's wrong with the completion stuff. But it should still be merged because it fixes a crash (pattern-match failure).