Added comments for various functions. Removed some dead code.