[Task] refactor code and add comments