Added error checking and added pdf