added fig1 code to a function