Updated lock and cleanup