Useful utility functions and such, cobbled together from various sources.