Added thread limit and flushed shared variables. Impressive performance boost