NXIDE-282  Refactoring and cleaning code, improving code design