improved plotting function