Fixed " index out of range" error