added array check for 0 index issue