move plotting code around