Refacroring: it works faster now