Fix references and clean