refactoring and bug fixing
updated