refactoring, fix errors