Threaded segments

Adds threaded segments as requested in #168.

TODO:

- [x] Fix documentation issues: `ThreadedSegment` class instances are not documented as functions. The question is [here](http://stackoverflow.com/questions/15454551/documenting-class-instance-as-a-function), but I guess I already knew the answer: I will have to write sphinx extension.
- [x] Finally add tests that are currently marked as TODO.
- [x] Fix #295, it is becoming worth now.