Stolen some helpers from another project