minor bug fix and arrange codes.