changed to use the solution @blag purposed