adding references and some rewrite