added lock, detailed errors