Improve error handling not to panic