One Button Two Functions bug fix

i already get the logic on how to switch on and off the relay, i just need help with the order since i can’t get around the fact that when the button is pressed again after a latched press, it writes relayp high again when it should only be relayn. maybe another variable that indicates the on position (if (relayp/led high…))?

right now the flow is: press, wait (debounce), if passed the debounce, activate LED and relayp, depending on how long the button was held, if held for more than 500ms, write relayn high and led low, or less than 500ms, latch led and relayp on and if pressed again, turn on relayn and led low. the problem is getting around that second press. how would i word a state that would get around the first initial part of the code? like two reading the switch points?