added more checking and an error