refining plot related code