Misc cleanups and improvements

This pull request is a collection of small code cleanups and improvements to the codebase