Code update and add comments