Modified script to make it faster