Changed the code to support keep-alive connection