DNN-5943 + CONTENT-2983 - Refactorized code, cleaned up code