Fix and cleanup a few things. Tests pass.