refined original with scipy