Revert previous (except stupid tests)
Alternative implementation from @kolmodin