raoxunrong, refactor code, move some behavior to independent classes.