--- a/MCEDisplayStyle.cpp
+++ b/MCEDisplayStyle.cpp
@@ -4,6 +4,7 @@
 #include "stdafx.h"
 #include "mce.h"
 #include "MCEDisplayStyle.h"
+#include "IO.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -30,15 +31,15 @@
 	//{{AFX_DATA_MAP(MCEDisplayStyle)
 		// NOTE: the ClassWizard will add DDX and DDV calls here
 	
-	DDX_Radio(pDX, IDC_DS_OFF, iDisplayStyle);
-	DDX_Text(pDX, IDC_DS_LINE_SIZE, fLineSize);
-	DDX_Text(pDX, IDC_DS_BALL_SIZE, fBallSize);
-	DDX_Text(pDX, IDC_DS_CYLINDER_SIZE, fCylinderSize);
-	DDX_Text(pDX, IDC_DS_SCALED_FACTOR, fScaledFactor);
-	DDX_Text(pDX, IDC_CYLINDER_RESOLUTION, fCylinderResolution);
-	DDX_Text(pDX, IDC_BALL_RESOLUTION, fBallResolution);
-	DDX_Text(pDX, IDC_SCALED_BALL_RESOLUTION, fScaledBallResolution);
-    DDX_Text(pDX, IDC_EDIT_LABEL_SIZE, iLabelSize);
+	DDX_Radio(pDX, IDC_DS_OFF, reinterpret_cast<int &> (DS.DisplayStyle));
+	DDX_Text(pDX, IDC_DS_LINE_SIZE, DS.LineSize);
+	DDX_Text(pDX, IDC_DS_BALL_SIZE, DS.BallSize);
+	DDX_Text(pDX, IDC_DS_CYLINDER_SIZE, DS.fCylinderSize);
+	DDX_Text(pDX, IDC_DS_SCALED_FACTOR, DS.ScaledFactor);
+	DDX_Text(pDX, IDC_CYLINDER_RESOLUTION, DS.fCylinderResolution);
+	DDX_Text(pDX, IDC_BALL_RESOLUTION, DS.fBallResolution);
+	DDX_Text(pDX, IDC_SCALED_BALL_RESOLUTION, DS.fScaledBallResolution);
+    DDX_Text(pDX, IDC_EDIT_LABEL_SIZE, DS.iLabelSize);
 	DDX_Control(pDX, IDC_SCALED_BALL_RESOLUTION, eScaledBallResolution);
 	DDX_Control(pDX, IDC_BALL_RESOLUTION, eBallResolution);
 	DDX_Control(pDX, IDC_CYLINDER_RESOLUTION, eCylinderResolution);
@@ -47,25 +48,25 @@
 	DDX_Control(pDX, IDC_DS_CYLINDER_SIZE, eCylinderSize);
 	DDX_Control(pDX, IDC_DS_SCALED_FACTOR, eScaledFactor);
 	DDX_Control(pDX, IDC_DS_BOND_VISIBLE, eBondsVisible);
-	DDX_Check(pDX, IDC_DS_BOND_VISIBLE, bBondsVisible);
+	DDX_Check(pDX, IDC_DS_BOND_VISIBLE, DS.bBondsVisible);
 	DDX_Control(pDX, IDC_MAP_LINE_SIZE, eMapLineSize);
 	DDX_Control(pDX, IDC_MAP_CYLINDER_SIZE, eMapCylinderSize);
-	DDX_Text(pDX, IDC_MAP_LINE_SIZE, fMapLineSize);
-	DDX_Text(pDX, IDC_MAP_CYLINDER_SIZE, fMapCylinderSize);
-	DDX_Radio(pDX, IDC_ELD_MAP_AS_LINE, iMapDisplayStyle);
-	DDX_Text(pDX, IDC_UNIT_CELL_LINE_SIZE, fUnitCellLineSize);
+	DDX_Text(pDX, IDC_MAP_LINE_SIZE, DS.fMapLineSize);
+	DDX_Text(pDX, IDC_MAP_CYLINDER_SIZE, DS.fMapCylinderSize);
+	DDX_Radio(pDX, IDC_ELD_MAP_AS_LINE, reinterpret_cast<int &> (DS.MapDisplayStyle));
+	DDX_Text(pDX, IDC_UNIT_CELL_LINE_SIZE, DS.fUnitCellLineSize);
 	DDX_Control(pDX, IDC_UNIT_CELL_LINE_SIZE, eUnitCellLineSize);
-	DDX_Check(pDX, IDC_DS_UNIT_CELL_VISIBLE, bUnitCellVisible);
+	DDX_Check(pDX, IDC_DS_UNIT_CELL_VISIBLE, DS.bUnitCellVisible);
 	DDX_Control(pDX, IDC_DS_UNIT_CELL_VISIBLE, eUnitCellVisible);
-	DDX_Text(pDX, IDC_ELD_MAP_CYLINDER_RESOLUTION, fMapCylinderResolution);
+	DDX_Text(pDX, IDC_ELD_MAP_CYLINDER_RESOLUTION, DS.fMapCylinderResolution);
 	DDX_Control(pDX, IDC_ELD_MAP_CYLINDER_RESOLUTION, eMapCylinderResolution);
-	DDX_Radio(pDX,IDC_COLORED_WITH_TWO_COLORS, iBondsColorStyle);
+	DDX_Radio(pDX,IDC_COLORED_WITH_TWO_COLORS, reinterpret_cast<int &> (DS.iBondsColorStyle));
 	DDX_Control(pDX, IDC_CHANGE_BOND_COLOR, eChangeBondsColor);
-	DDX_Check(pDX, IDC_CHECK1, bOrganic);
-	DDX_Check(pDX, IDC_CHECK2, bLoadMapSettings);
-    DDX_Check(pDX, IDC_CHECK_SHOW_LABELS, bShowAtomicLabels);
-    DDX_Check(pDX, IDC_CHECK_SHOW_HYDROGENS_LABELS, bShowHLabels);
-    DDX_Check(pDX, IDC_CHECK3, bMapsEdgesVisible);
+	DDX_Check(pDX, IDC_CHECK1, DS.bOrganic);
+	DDX_Check(pDX, IDC_CHECK2, DS.bLoadMapSettings);
+    DDX_Check(pDX, IDC_CHECK_SHOW_LABELS, DS.bShowLabels);
+    DDX_Check(pDX, IDC_CHECK_SHOW_HYDROGENS_LABELS, DS.bShowHLabels);
+    DDX_Check(pDX, IDC_CHECK3, DS.bDrawMapEdges);
     DDX_Control(pDX, IDC_CHECK_SHOW_LABELS, eShowAtomicLabels);
     DDX_Control(pDX, IDC_CHECK_SHOW_HYDROGENS_LABELS, eShowHLabels);
 	//}}AFX_DATA_MAP
@@ -142,7 +143,7 @@
 
 void MCEDisplayStyle::SetEditVisibility()
 {
-	switch (iDisplayStyle)
+	switch (DS.DisplayStyle)
 	{
 	case 0:
 		MCEDisplayStyle::OnDsOff();
@@ -164,7 +165,7 @@
 		break;
 	}
 
-	switch (iMapDisplayStyle)
+	switch (DS.MapDisplayStyle)
 	{
 	case 0:
 		MCEDisplayStyle::OnEldMapAsLine();
@@ -174,7 +175,7 @@
 		break;
 	}
 	
-	switch (iBondsColorStyle)
+	switch (DS.iBondsColorStyle)
 	{
 	case 0:
 		MCEDisplayStyle::OnColoredWithTwoColors();
@@ -358,72 +359,19 @@
 }
 void MCEDisplayStyle::OnSaveSettings() 
 {
-	char szBuffer[255];
+
 	// TODO: Add your control notification handler code here
 		
-		CDialog::UpdateData(TRUE);
-
-		VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
-
-		CString sPath = (CString)szBuffer;
-		sPath = sPath.Left(sPath.ReverseFind('\\'));	
-
-		sPath=sPath+"\\Settings.txt";
-
-		CFile f( sPath, CFile::modeCreate | CFile::modeWrite);
-		CArchive ar(&f,CArchive::store);
-	
-		ar.WriteString("		-- MCE Display style settings --		\n");
-		ar.WriteString("		     -- generated by MCE --				\n\n");
-
-		ar.WriteString("Molecule display style\n");
-		sprintf(szBuffer,"DisplayStyle		%d\n", iDisplayStyle);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"BondsVisible		%d\n", bBondsVisible);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"LineSize		%f\n", fLineSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"BallSize		%f\n", fBallSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"CylinderSize		%f\n", fCylinderSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"ScaledFactor		%f\n", fScaledFactor);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"BallResolution		%f\n", fBallResolution);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"CylinderResolution	%f\n", fCylinderResolution);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"ScaledBallResolution	%f\n", fScaledBallResolution);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"BondsColorStyle		%d\n", iBondsColorStyle);
-		ar.WriteString(szBuffer);		
-		sprintf(szBuffer,"Red			%f\n", BondsColor[0]);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"Green			%f\n", BondsColor[1]);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"blue			%f\n", BondsColor[2]);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"MapDisplayStyle		%d\n", iMapDisplayStyle);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"MapLineSize		%f\n", fMapLineSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"MapCylinderSize		%f\n", fMapCylinderSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"MapCylinderResolution	%f\n", fMapCylinderResolution);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"UnitCellVisible		%d\n", bUnitCellVisible);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"UnitCellLineSize	%f\n", fUnitCellLineSize);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"Organic	%d\n", bOrganic);
-		ar.WriteString(szBuffer);
-		sprintf(szBuffer,"LoadMapSettings	%d\n", bLoadMapSettings);
-		ar.WriteString(szBuffer);
-        sprintf(szBuffer,"MapsEdgesVisible	%d\n", bMapsEdgesVisible);
-		ar.WriteString(szBuffer);
-
-		ar.Close();
-		f.Close();
+	CDialog::UpdateData(TRUE);
+    
+    char szBuffer[255];
+	VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
+
+	CString sPath = (CString)szBuffer;
+	sPath = sPath.Left(sPath.ReverseFind('\\'));	
+
+	sPath=sPath+"\\Settings.txt";
+    IO::SaveDisplayStyleSettings(sPath, DS);		
 }
 
 void MCEDisplayStyle::OnLoadDefault() 
@@ -431,82 +379,50 @@
 	CString strInputData;
 	char szBuffer[255];
 	// TODO: Add your control notification handler code here
-
-		VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
-
-		CString sPath = (CString)szBuffer;
-		sPath = sPath.Left(sPath.ReverseFind('\\'));	
-
-		sPath=sPath+"\\DefaultSettings.txt";
-
-
-		CFile f(sPath, CFile::modeRead);
-		CArchive ar(&f,CArchive::load);
-
-		ar.ReadString(strInputData);
-		ar.ReadString(strInputData);
-		ar.ReadString(strInputData);
-		ar.ReadString(strInputData);
-
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&iDisplayStyle);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&bBondsVisible);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fLineSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fBallSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fCylinderSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fScaledFactor);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fBallResolution);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fCylinderResolution);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fScaledBallResolution);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&iBondsColorStyle);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&BondsColor[0]);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&BondsColor[1]);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&BondsColor[2]);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&iMapDisplayStyle);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fMapLineSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fMapCylinderSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fMapCylinderResolution);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&bUnitCellVisible);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %f",&szBuffer,&fUnitCellLineSize);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&bOrganic);
-		ar.ReadString(strInputData);
-		sscanf(strInputData,"%s %d",&szBuffer,&bLoadMapSettings);        
-
-		ar.Close();
-		f.Close();
-		CDialog::UpdateData(FALSE);
-		MCEDisplayStyle::SetEditVisibility();
+    DS.DisplayStyle = (DisplayStyleMode) 4;
+    DS.bBondsVisible = TRUE;
+    DS.LineSize = 2.0;
+    DS.BallSize = 0.2;
+    DS.fCylinderSize = 0.08;
+    DS.ScaledFactor = 0.22;
+    DS.fBallResolution = 30.0;
+    DS.fCylinderResolution = 20.0;
+    DS.fScaledBallResolution = 30.0;
+    DS.iBondsColorStyle = (BondsColorStyle) 0;
+    DS.BondsColor[0] = 127;
+    DS.BondsColor[1] = 127;
+    DS.BondsColor[2] = 127;
+    DS.MapDisplayStyle = (MapDisplayStyleMode) 0;
+    DS.fMapLineSize = 1.3;
+    DS.fMapCylinderSize = 0.015;
+    DS.fMapCylinderResolution = 6.0;
+    DS.bUnitCellVisible = TRUE;
+    DS.fUnitCellLineSize = 1.3;
+    DS.bOrganic = TRUE;
+    DS.bLoadMapSettings = FALSE;
+    DS.bDrawMapEdges = FALSE;
+
+	VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
+	CString sPath = (CString)szBuffer;
+	sPath = sPath.Left(sPath.ReverseFind('\\'));	
+	sPath=sPath+"\\DefaultSettings.txt";
+      
+    IO::LoadDisplayStyleSettings(sPath, DS);
+	
+	CDialog::UpdateData(FALSE);
+	MCEDisplayStyle::SetEditVisibility();
 }
 HBRUSH MCEDisplayStyle::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor)
 {
    CBrush m_brush;
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    if (pWnd->GetDlgCtrlID() == IDC_EDIT_LABEL_COLOUR) {
-      m_brush.CreateSolidBrush(RGB(LabelsColor[0], LabelsColor[1], LabelsColor[2]) );      
+      m_brush.CreateSolidBrush(RGB(DS.LabelsColor[0]*255, DS.LabelsColor[1]*255, DS.LabelsColor[2]*255) );      
       if (m_brush.GetSafeHandle())
 		hbr = m_brush;
    }    
    if (pWnd->GetDlgCtrlID() == IDC_EDIT_BOND_COLOUR) {
-      m_brush.CreateSolidBrush(RGB(BondsColor[0], BondsColor[1], BondsColor[2]) );      
+      m_brush.CreateSolidBrush(RGB(DS.BondsColor[0]*255, DS.BondsColor[1]*255, DS.BondsColor[2]*255) );      
       if (m_brush.GetSafeHandle())
         hbr = m_brush;
    } 
@@ -525,13 +441,16 @@
 	if(dlg.DoModal() == IDOK)
 	{
 		color=dlg.GetColor();
-		BondsColor[2]=((float)(((color) >> 16) & 0xff));
-		BondsColor[1]=((float)(((color) >> 8) & 0xff));
-		BondsColor[0]=((float)((color) & 0xff));
-		
-	
-		//glClearColor( BackgrounColor.R, BackgrounColor.G, BackgrounColor.B, 0.0f );
-		
+        DS.BondsColor[0] = (float) (GetRValue(color)) / 255;
+        DS.BondsColor[1] = (float) (GetGValue(color)) / 255;
+        DS.BondsColor[2] = (float) (GetBValue(color)) / 255;
+		/*
+        DS.BondsColor[2]=((float)(((color) >> 16) & 0xff));
+		DS.BondsColor[1]=((float)(((color) >> 8) & 0xff));
+		DS.BondsColor[0]=((float)((color) & 0xff));
+        */		
+	
+		//glClearColor( BackgrounColor.R, BackgrounColor.G, BackgrounColor.B, 0.0f );		
 		Invalidate(TRUE);
 	}
     /*
@@ -587,9 +506,14 @@
 	if(dlg.DoModal() == IDOK)
 	{
 		color=dlg.GetColor();
-		LabelsColor[2]=((float)(((color) >> 16) & 0xff));
-		LabelsColor[1]=((float)(((color) >> 8) & 0xff));
-		LabelsColor[0]=((float)((color) & 0xff));
+        DS.LabelsColor[0] = (float) (GetRValue(color)) / 255;
+        DS.LabelsColor[1] = (float) (GetGValue(color)) / 255;
+        DS.LabelsColor[2] = (float) (GetBValue(color)) / 255;
+        /*
+		DS.LabelsColor[2]=((float)(((color) >> 16) & 0xff));
+		DS.LabelsColor[1]=((float)(((color) >> 8) & 0xff));
+		DS.LabelsColor[0]=((float)((color) & 0xff));
+        */
 		
 	
 		//glClearColor( BackgrounColor.R, BackgrounColor.G, BackgrounColor.B, 0.0f );