major changes, mostly to accomodate functions