Add more defensive code