suggestions on cleaning this up? i tested against the example url you gave me and this seems to work, but it's not the clearest code.