code clean and minor bug fix