fixed takeAll() time complexity