small changes, error checking.