Made removeFirst and replaceFirst to support thread-safe