This might be what you need for your middle bit, or the background, but I've not read the thread properly.