Fixed segfaults that occur due to incorrectly assigning variable indices as variables