added 3rd stage for applying support functions. (which fixed some calculation bugs)