fixed bug and code improvement