Fixed sql for computing complement and reverted counter change back to AtomicInteger