Converted code to use ESI