Cleaned up plotting function