fixing everything except some function definitions