Some improvement and code refactor.