code refactoring
refactoring and bug fixes