add methods.
move some methods to models.
add doc.
Merge branch 'refctoring'