Fix bugs in Firefox, add randomness to id generation