bugfixes & flexibility

fixed a really nasty TPQ-based bug, which required some general
improvements to do.