speed function added (with bugs)