Thanks to thierryvolpiatto for the improved function\!