Applied working code to index from reference