Untested, first optimized version.