Fixed up some things, added some functions, added some documentation