Refactor code into a StripPrefix function