test1-4.sh working. Fixed index bug. Added memory deallocation.