Refactoring + Cleanup
(cherry picked from commit 573065c)
(cherry picked from commit 049cea1)