Changed the order of for loop and try block to writeStats all the entries