Refactor to remove nested cases