refactoring and further stealing from GLPlot