Cleaned up the plot logic