Final version. Removed debugging printings and comments.
Add some document for methods.