minor #cleanup: func now deals with errors