Small refactorings and fixes better localization