bug fix & code refactor