fix bugs and refactoring
merge