updated some uncommited code from Juha, Marc-Jan and Harm-Jan