Formatting and other functions

Format messages and queries and perform other useful operations.