Small bug fixed and refactoring.