Fully commented for clarity