Rearranged code into partials

[Fixes 50955021]