Added code comments for all functions
Minor code revises