Fix derp

(cherry picked from commit 2d95f7291bf91eab191cd5806007bb06a3eb06a4)
Refactoring

(cherry picked from commit b203ae082c0dacc50303658fd409ce232ec1711c)