changing the structure to reuse some code in RDM computation