Thanks for the fix. Also made the change to remove the duplicate code.
I saw in the code if the main admin was not set, it would just take number 2, without a check if it was an admin or not. I would suggest a query that takes the first admin user from the userlist.
At our board user number 2 is an ex-admin who left.