bug fix & code refactoring