cleaned Badge code.
fixed race condition in Badge update.