Improved function that removes trailing spaces and added some mappings