really, really super ugly code. may work. cleanup.