ugly but it works