worked through some of the substitute function