Improve escape function