Refactored localize code