While this is indeed clean, consider that I inlined the code for performance reasons