reduced redundancy using function for plot