Pull dev branch into master

Major code restructure.