major refactor, support transactions and implementing counters