Attempt at adding error checking