this is a rats nest, but it works (I think)