bug fix & refactoring.