@pfaffman It looks like the simplest change to the second problem is to replace:
local RESOLVED_IP=`dig +short $1`
with
local RESOLVED_IP=`dig +short $1 | tail -1`
This will ensure that the final answer from dig, which should be the actual IP address, is what is then used by the rest of the script.