adding basic error checking and logging