Some cleanups and fixes