Some minor cleanups and improved feature detection