ugly, but working code