I think I have fixed it. But it might be a bit of a hack.