adding in some error checking