better implementation that is based on my PR. this will be removed once the PR got pulled