added error checking stuff