Closes #14. Elegant handling of API chaining.

... and a complete refactoring as well.