OK, MikroTik support was friendly but in the end I found the problem myself. The first problem is that the script runs twice when releasing the IP address. You therefore have to make sure that the IP address is bound by checking for $bound=1. The second problem is that the dhcp-client lease script r...