Clean

Cleaned up unused variables, typo in a variable, some local variables not defined properly, events not used in some functions, invalid returns, etc.