Refactor: extract functions for surrounding and replacing