simplifed some logic