Trying to fix plotting function