ugly but working architecture