Optimize file extension handling in several places