Aplied patch from LARC

This was a second patch from LARC and had to be partly applied by hand.