moving check into if statement's scope