apply EitherT to remove nested if statements