isn't there a simpler way? this looks very complicated... or maybe I don't understand it...