Removed use of jQuery $ variable. Added basic error handling for arrays.