Several bugs corrected, added a transaction counter