Refactored string_substitution.hs to make it cleaner and faster.