fix bug, speed up script