Ugly but works