You could reuse the method from my last comment here