Added error checking and filepath