Improve key transform functions and add scaling macro