various fixes, cleanups. Now handles nested references, cleaned the
reference part, passed more tests
cleaned debugs infos