Various fixes and refatoring on localization