Refactoring + Cleanup
(cherry picked from commit 573065c)