Added the urlEncode function to clean up the code a little more.