Add more checks to avoid errors