Refactor deduplicate slug method

Previously this method was called with a `this` value, which made the
code a little opaque. This makes it a regular function that doesn't
depend on the current value of 'this'.