changes to context, restructured functions to fit #7