Refactored the code for NING-13267