Miscellaneous python functions