Code duplication

This branch includes various code optimizations aiming at removing code duplication.

It also introduces a new filterMap method.