index access and variable declaration bug fixed