Miscellaneous useful bits of code