Increase test coverage and return errors instead of panic