added missing libraries, mode plotting code