made some optimisations, and fixed the way fieldswere being searched