move working code from reference to index