improved (slightly) error handling and updated tests to avoid try catch