reformat code to standard and fixing add cookie handler.