Bug fix: Fix access to freed memory due to invalid w->prev_trans

- Fix a bug that w->prev_trans sometimes points to freed memory.
  Probably related to #165.

- Add some more debugging printf()-s under DEBUG_EVENTS.