Minor code quality improvements

Some deduplication and cleanup