Fixed issue #1355. Speeded up also execution by using only 1 transaction and applying the condition filter to the query too