Refatoring; Useless queries reduce and more