added logical handling for race conditions in Key class