Added working code from reference to index