refactoring tx logic
wr.c