Some refactoring.

Signed-off-by: ushi <ushi@porkbox.net>