Refactor large amounts of code.
Improved readability and maintainability.
Split last friends generation phases and serialization