added the racing logic but still needs work