Finished substitute function