Fixed plotting function