Trouble with rotating camera around object

Hey, guys. I’m working on a camera script that is intended to rotate the camera around the player object on both the x and y axis. I’ve gotten pretty close to making it work, but am stuck on the fact that my y axis seems to flip orientation when I rotate around the back side of the player. For example, moving the cursor up on the front side rotates the camera up, but once I’ve rotated around the back side of the player it rotates the camera down. Can’t figure out how to fix it for the life of me. Any suggestions would be appreciated.

    void CameraRotation()
    {
        //Get start position of cursor
        if (isRunOnce == false)
        {
            startPositionX = Input.mousePosition.x;
            startPositionY = Input.mousePosition.y;
            isRunOnce = true;
        }
        //X Axis rotation
        rotatePositionX = Input.mousePosition.x - startPositionX;
        transform.RotateAround(target.position, target.up, rotatePositionX * Time.deltaTime);

        //Y Axis rotation
        rotatePositionY = Input.mousePosition.y - startPositionY;
        transform.RotateAround(target.position, target.right, rotatePositionY * Time.deltaTime);

        //Keeps camera rotation properly oriented.
        transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0f);
    }

Solved it. For anyone looking for answers in the future, pay attention to the change I made in line 16. I changed target.right to transform.right.

    void CameraRotation()
    {
        //Get start position of cursor
        if (isRunOnce == false)
        {
            startPositionX = Input.mousePosition.x;
            startPositionY = Input.mousePosition.y;
            isRunOnce = true;
        }
        //X Axis rotation
        rotatePositionX = Input.mousePosition.x - startPositionX;
        transform.RotateAround(target.position, target.up, rotatePositionX * Time.deltaTime);

        //Y Axis rotation
        rotatePositionY = Input.mousePosition.y - startPositionY;
        transform.RotateAround(target.position, transform.right, rotatePositionY * Time.deltaTime);

        //Keeps camera rotation properly oriented.
        transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0f);
    }