implementation from ueler forum, fitted into method and called from test