unreferenced (and possibly buggy) code removed
free allocated memory as early as possible
ifdef for variable declaration
unused local variables removed
unused global variables removed
extra semicolon removed