refactored to simplify use of plans