mostly converted, apart from the main join function