refactoring, fixes