Copy code frome google code, fix stop time crash