proper error handling instead of panics