refactored to tighter planning code