Added generic support for join (thanks to jeannicolas)