Refactored a large amount of result building code for improved readability and performance.