Optimize and streamline the hasModes function.