Further refactored data formatting method.