update code with yawen's PR