encapsulated plot and barplot. cleaned up code (and needs more cleanup)