Improved escape function.