bug fix & refactor code.