improving methods from bill-the-lizard's answer - like it better.