a few code refactor