re-structuring algorithm and re-implementation of form creation