Cleaned up logic for scenario handling.