Fixed a bug with joins - although the solutions screams for further optimization