Clean things up, fix a few bugs