cleaned up and commented
added handling of variables with no dictionary index