Updated javascript, fixed issues with setTimeout