Generic handler function.