DNN-5733 - Added further refactoring and fixes after code review