Code style cleanups, unused code removal, minor bug fixes