A little ugly using dynamic variables, but it works.