Implement path compression