rebuild datas logic using $q