fix overreading bug
refactoring tx logic