Generic solution for selects

Keep the special cases, as they generate smaller
constraints.
Merge pull request #14 from jeroenk/select

Generic solution for selects