improve speed to the algorithm
now, it can be done in real time, but the script is quite messy now....