Fixup a few undefined variables

Added some documentation bits at the same time

Remove unused globals/variables

Change-Id: I354915a5004495add35f3c0b949aafcc29448e1e