replaced index() with index iterator or each function
Improved naming and declared all variables at one place