Refactored parameters and return values for more flexible error messages