Some cleanups and robustness fixes