Refactoring of NMS code. Can support multiple versions, if I wanted it to!