Added substitute function and test