Remove unused functions and add comments to all functions