speed function added (less bugs now)