replaced error prints with error returns