added in more error checking