Fix bug: tabs dimmed in background would never be revealed afterwards.

Also added tracing functionality and cleaned up code a bit.