Added a check function before plotting