Helper functions almost all done. Main body under construction.