Fixing query time out

Adding garbage collection