first version. not efficient