Code cleanup. Decalring of variables, indication of use of globals, missing semi-colon addition, removal of unused variables