Added stop function. Fixed bugs.