adapt changes proposed by peterfri - thank you!