group if conditions in correct way