Switch to a while loop to make things clear and readble. Also properly set zone dedicated rules in the rules/pipes DBs to properly release when a zone is deactivated