bug fix & refractor