Another massive overhaul of lots of functions. Also added a timing test and analysis function for a timing test.