Formatting and encoding response