Refactored to use inlines to achieve hand-unrolled loops