Addded a bunch of functions, removed unused stuff