d changed condense function, need to test and debug