Misc fixes

This patch provides some cleanups and minor fixes.