Removed unused variables/functions, inserted comments