code clean and check in this working version