At this point its pretty clear that you have multiple sections of code that are looking to !permit and delete links. That's not gonna work. You need to go through your mess of a script and do some house keeping.