updated index and logic