Greatly improve the extract method thanks to @xabbuh's suggestions