Improved method of substitution, thanks @rmcastil