Misc. utility code