A bit nasty but works