Made check for locked when leaving object