Tidying up the code using an Either.

Thanks Phil!