major tidy up, and moved everything to v2 with declare to improve readability