undefined fixed and refactoring