add more error checking logic