refactored code to fit architecture, added indices