added error checking and passing argument in