Various fixes for NameAnalysis and more tests