added array check as per js suggestion