phases 1, 2 and 4 complete with a few fixes