Move environment check into a separate method