Fixed the bug.
refactored.