Query, Delete and other optimization