Improved trim functions (trim, ltrim, rtrim)