Added automic operations to avoid race conditions. -Devan