Refactor apply_slug