Merge Panda's changes and refactor.