Second time pause menu is opened can't be closed by key

I’m pretty sure there’s nothing interacting with it outside this script, but the second time I open the menu I can’t close it by pressing escape anymore. everything else works fine and escape will still close the options but that won’t work.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class pauseMenu : MonoBehaviour
{
   public bool IsPaused = false;
    public GameObject PauseMenu;
    public GameObject OptionsMenu;
    public bool OptionsOpened = false;
    private OptionsMenu optionsMenu;
    public GameObject optionsSettings;

    public static pauseMenu instance;


    void Awake()
    {   
        Cursor.lockState = CursorLockMode.Locked;
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(this);
    }

    public void Update()
    {

        if (IsPaused)
        {
            Cursor.lockState = CursorLockMode.None;
        }
        else
        {
            Cursor.lockState = CursorLockMode.Locked;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (IsPaused && !OptionsOpened)
            {
                Resume();
            } if (!IsPaused)
            {
                Pause();
            } 
            
            if (OptionsOpened)
            {
                CloseOptions();
            }
        }
    }

    public void Resume()
    {
        PauseMenu.SetActive(false);
        Time.timeScale = 1;
        IsPaused = false;
    }

    void Pause()
    {
        PauseMenu.SetActive(true);
        Time.timeScale = 0;
        IsPaused = true;
    }

    public void OpenOptions()
    {
        OptionsOpened = true;
        PauseMenu.SetActive(false);
        OptionsMenu.SetActive(true);
    }

    public void CloseOptions()
    {           
        optionsMenu = optionsSettings.GetComponent<OptionsMenu>();
        OptionsOpened = false;
        PauseMenu.SetActive(true);
        optionsMenu.SaveSettings();
        OptionsMenu.SetActive(false);

    }

    public void QuitGame()
    {
        Time.timeScale = 1.0f;
        Destroy(gameObject);
        PauseMenu.SetActive(false);
        SceneManager.LoadScene(0);
    }

    public void KillGame()
    {
        Application.Quit();
    }
}

Also sorry for it being kind of a mess, I’ve been mangling tons of things around and trying stuff to get it working

Fixed it by formatting it like this

if (Input.GetKeyDown(KeyCode.Escape) && !OptionsOpened)
{
    if (!IsPaused)
    {
        Pause();
    } else
    {
        Resume();
    } 
}

if (Input.GetKeyDown(KeyCode.Escape) && OptionsOpened)
{
    CloseOptions();
}

It makes no sense, I tried to set it like a dozen different ways that definitely should’ve worked fine, but this specifically is the only way that won’t break it for some reason