That looks pretty heavy-weight compared to this logic which was lifted from 3.x