Improved translate function