Misc utilities and common functions