refactored some code and updated index template