func now deals with errors