added index and revised code