Updated php logic improved style