Various cleanups/fixes. Tests pass.