Refactored index + completed algo1