making the code more defensive