fix bugs. refactor.