Add comments and change two function definitions