change few static variables to non-static. make sure all error info are written to file properly.
remove unnecessary trailing whitespaces.