Refactored indexes with variables. Added summing functionality