Bug fixed and refactoring.