This looked nicer, but GCC couldn't optimize it.