refactored plotting