Refactored some code.
Added some documents.