added error outputs and return type