first changes by Pascal to allow searching also entities + minor code cleanup