code clean and bug fixes