completed code for Term plan arrangement