faster implementations of useful python functions