Whoa, that turned out far more complicated than I expected!