Addition to close function

also redid a few functions