Resolve references and some fix