Added null check for encodeUrl()