ugly but working