Added logic to manage instance locks