added lock for SQL