Some cleanups and restructuring