The `raise` statements in this method should probably raise meaningful exceptions rather than just strings.