Added proper handling of indexing variables