cleaning up the code and adressing (partly?) the issue of windows appearing below terminal on some platforms.