Various cleanups and fixes