Avoid using panic when possible and instead return an error. Only panic at the topmost level of functions.