Fix some bugs with main transaction