Checked doc and refactored some code.