Return err instead of panicking