Index: src/globals.cpp
===================================================================
--- src/globals.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/globals.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -24,7 +24,21 @@
 #include "globals.h"
 
+#include <QFile>
+#include <QObject>
+#include <QSettings>
+#include <QWidget>
+
 #ifdef Q_OS_WINCE_WM
 #   include <shellapi.h>
 #endif
+
+bool hasUpdater()
+{
+#ifdef Q_OS_WIN32
+    return QFile::exists("updater/Update.exe");
+#else // Q_OS_WIN32
+    return false;
+#endif // Q_OS_WIN32
+}
 
 QSettings *initSettings(QObject *parent)
Index: src/globals.h
===================================================================
--- src/globals.h	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/globals.h	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -30,5 +30,5 @@
 
 // INCLUDES
-#include <QtCore>
+#include <QtGlobal>
 #if QT_VERSION < QT_VERSION_CHECK(4,5,0)
 #   error You are using Qt version < 4.5 but minimum required version is 4.5.0. Compilation aborted.
@@ -39,32 +39,10 @@
 #   define QT_NO_STATUSTIP
 #endif
-#include <QtGui>
 #if defined(QT_NO_SVG) && !defined(NOSVG)
 #   define NOSVG
 #endif
-#if !defined(NOSVG)
-#   include <QtSvg>
-#endif // NOSVG
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
-#   include <QtConcurrent>
-#   include <QtPrintSupport>
-#endif
 
-#ifndef HANDHELD
-#   include "qttoolbardialog.h"
-#endif
-
-// Version info
-#include "version.h"
-// OS and ARCH detection
-#include "os.h"
 // TSPSG Defaults
 #include "defaults.h"
-// TSPSolver
-#include "tspsolver.h"
-#ifndef HANDHELD
-    // Eyecandy
-#   include "qtwin.h"
-#endif // HANDHELD
 
 // DEFINES
@@ -84,5 +62,5 @@
 /*!
  * \def PATH_DOCS
- * \brief Bath to documentation files.
+ * \brief Path to documentation files.
  */
 #ifndef PATH_DOCS
@@ -111,16 +89,4 @@
 #define HQ_FACTOR 2
 
-// FUNCTIONS
-/*!
- * \brief Checks whether \a x contains an integer value.
- * \param x A value to check.
- * \return \c true if \a x countains an integer, oherwise \c false.
- */
-inline bool isInteger(double x)
-{
-double i;
-    return (modf(x, &i) == 0.0);
-}
-
 /*!
  * \brief Checks whether the updater app is installed/available.
@@ -129,29 +95,8 @@
  *  On other systems this function always returns \c false.
  */
-inline bool hasUpdater()
-{
-#ifdef Q_OS_WIN32
-    return QFile::exists("updater/Update.exe");
-#else // Q_OS_WIN32
-    return false;
-#endif // Q_OS_WIN32
-}
+bool hasUpdater();
 
-/*!
- * \brief Converts \a in into Base64 format with lines wrapped at 64 characters.
- * \param in A byte array to be converted.
- * \return Converted byte array.
- */
-inline QByteArray toWrappedBase64(const QByteArray &in)
-{
-    QByteArray out, base64(in.toBase64());
-    for (int i = 0; i <= base64.size() - 64; i += 64) {
-        out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n');
-    }
-    if (int rest = base64.size() % 64)
-        out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest));
-    return out;
-}
-
+class QSettings;
+class QObject;
 /*!
  * \brief Creates QSettings instance with TSPSG-specific options.
@@ -162,4 +107,5 @@
 
 #ifndef HANDHELD
+class QWidget;
 /*!
  * \brief Enables or disables a mask for the \a widget.
@@ -173,9 +119,4 @@
 
 #ifndef DOXYGEN_EXCLUDE
-
-#ifndef QT_NO_PRINTER
-    Q_DECLARE_METATYPE(QPrinter::PageSize)
-    Q_DECLARE_METATYPE(QPrinter::Orientation)
-#endif
 
 #ifdef HANDHELD
Index: src/main.cpp
===================================================================
--- src/main.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/main.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -23,4 +23,11 @@
 
 #include "mainwindow.h"
+
+#include <QDateTime>
+#include <QFontDatabase>
+#include <QTextCodec>
+#include <QTranslator>
+#include "version.h"
+
 #if QT_VERSION < QT_VERSION_CHECK(4,6,0)
 #   ifdef Q_CC_MSVC
Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/mainwindow.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -23,4 +23,60 @@
 
 #include "mainwindow.h"
+#include "settingsdialog.h"
+#include "tspmodel.h"
+
+#include <QBuffer>
+#include <QCloseEvent>
+#include <QDate>
+#include <QDesktopServices>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QImageWriter>
+#include <QLibraryInfo>
+#include <QMessageBox>
+#include <QPageSetupDialog>
+#include <QPainter>
+#include <QProgressBar>
+#include <QProgressDialog>
+#include <QSettings>
+#include <QStatusBar>
+#include <QStyleFactory>
+#include <QTextCodec>
+#include <QTextDocumentWriter>
+#include <QTextBrowser>
+#include <QTextStream>
+#include <QTextTable>
+#include <QTranslator>
+
+#ifdef Q_OS_WINCE_WM
+#   include <QScrollArea>
+#endif
+
+#ifndef QT_NO_PRINTER
+#   include <QPrinter>
+#   include <QPrintDialog>
+#   include <QPrintPreviewDialog>
+#endif
+
+#if !defined(NOSVG)
+#   include <QSvgGenerator>
+#endif // NOSVG
+
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+#   include <QtConcurrent>
+#endif
+
+#include "os.h"
+
+#ifndef HANDHELD
+#   include "qttoolbardialog.h"
+    // Eyecandy
+#   include "qtwin.h"
+#endif // HANDHELD
+
+#ifndef QT_NO_PRINTER
+    Q_DECLARE_METATYPE(QPrinter::PageSize)
+    Q_DECLARE_METATYPE(QPrinter::Orientation)
+#endif
 
 #ifdef Q_OS_WIN32
@@ -32,4 +88,33 @@
 _C_ _R_ _Y_ _P_ _T_
 #endif
+
+// BEGIN HELPER FUNCTIONS
+/*!
+ * \brief Checks whether \a x contains an integer value.
+ * \param x A value to check.
+ * \return \c true if \a x countains an integer, oherwise \c false.
+ */
+inline bool isInteger(double x)
+{
+double i;
+    return (modf(x, &i) == 0.0);
+}
+
+/*!
+ * \brief Converts \a in into Base64 format with lines wrapped at 64 characters.
+ * \param in A byte array to be converted.
+ * \return Converted byte array.
+ */
+inline QByteArray toWrappedBase64(const QByteArray &in)
+{
+    QByteArray out, base64(in.toBase64());
+    for (int i = 0; i <= base64.size() - 64; i += 64) {
+        out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n');
+    }
+    if (int rest = base64.size() % 64)
+        out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest));
+    return out;
+}
+// END HELPER FUNCTIONS
 
 /*!
@@ -571,5 +656,5 @@
 #endif
     about += tr("Build <b>%1</b>, built on <b>%2</b> at <b>%3</b>%5 with <b>%4</b> compiler.").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__).arg(COMPILER).arg(tag) + "<br>";
-    about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId());
+    about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), TSPSolver::CTSPSolver::getVersionId());
     about += "<br>";
     about += tr("This program is free software: you can redistribute it and/or modify<br>\n"
@@ -738,8 +823,8 @@
 void MainWindow::buttonSolveClicked()
 {
-TMatrix matrix;
-QList<double> row;
-int n = spinCities->value();
-bool ok;
+    TSPSolver::TMatrix matrix;
+    QList<double> row;
+    int n = spinCities->value();
+    bool ok;
     for (int r = 0; r < n; r++) {
         row.clear();
@@ -784,5 +869,5 @@
 #endif
 
-CTSPSolver solver;
+    TSPSolver::CTSPSolver solver;
     solver.setCleanupOnCancel(false);
     connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
@@ -792,5 +877,5 @@
         connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int)));
 #endif
-SStep *root = solver.solve(n, matrix);
+    TSPSolver::SStep *root = solver.solve(n, matrix);
 #ifdef Q_OS_WIN32
     if (tl != NULL)
@@ -821,5 +906,5 @@
 
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+        QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
         while (!f.isFinished()) {
             QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -899,12 +984,12 @@
     cur.insertHtml("<hr>");
     cur.insertBlock(fmt_paragraph);
-int imgpos = cur.position();
+    int imgpos = cur.position();
     cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
     cur.endEditBlock();
 
-SStep *step = root;
-int c = n = 1;
+    TSPSolver::SStep *step = root;
+    int c = n = 1;
     pb->setFormat(tr("Generating step %v"));
-    while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) {
+    while ((step->next != TSPSolver::SStep::NoNextStep) && (c < spinCities->value())) {
         if (pd.wasCanceled()) {
             pd.setLabelText(tr("Memory cleanup..."));
@@ -918,5 +1003,5 @@
 #endif
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+            QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
             while (!f.isFinished()) {
                 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -952,7 +1037,7 @@
         else
             cur.insertBlock(fmt_paragraph);
-        cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
+        cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == TSPSolver::SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
         if (!step->alts.empty()) {
-            SStep::SCandidate cand;
+            TSPSolver::SStep::SCandidate cand;
             QString alts;
             foreach(cand, step->alts) {
@@ -974,8 +1059,8 @@
         n++;
 
-        if (step->next == SStep::RightBranch) {
+        if (step->next == TSPSolver::SStep::RightBranch) {
             c++;
             step = step->prNode;
-        } else if (step->next == SStep::LeftBranch) {
+        } else if (step->next == TSPSolver::SStep::LeftBranch) {
             step = step->plNode;
         } else
@@ -1052,5 +1137,5 @@
 #endif
 #ifndef QT_NO_CONCURRENT
-QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);
+    QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false);
     while (!f.isFinished()) {
         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
@@ -1211,5 +1296,5 @@
 }
 
-void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
+void MainWindow::drawNode(QPainter &pic, int nstep, bool left, TSPSolver::SStep *step)
 {
 qreal r; // Radius of graph node
@@ -1268,5 +1353,5 @@
         pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
     } else if (nstep > 1) {
-        pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
+        pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == TSPSolver::SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
     }
 
@@ -1563,5 +1648,5 @@
 }
 
-void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix)
+void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix)
 {
 int n = spinCities->value();
@@ -1583,5 +1668,5 @@
 }
 
-void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step)
+void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step)
 {
 int n = spinCities->value();
@@ -1597,5 +1682,5 @@
                 cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_selected);
             else {
-SStep::SCandidate cand;
+    TSPSolver::SStep::SCandidate cand;
                 cand.nRow = r;
                 cand.nCol = c;
Index: src/mainwindow.h
===================================================================
--- src/mainwindow.h	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/mainwindow.h	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -32,7 +32,7 @@
 
 #include "ui_mainwindow.h"
-#include "settingsdialog.h"
+#include "tspsolver.h"
 
-#include "tspmodel.h"
+#include <QPicture>
 
 #ifdef Q_OS_WIN32
@@ -41,5 +41,14 @@
 #endif
 
-using namespace TSPSolver;
+class CTSPModel;
+
+#ifndef HANDHELD
+    class QtToolbarDialog;
+    class QtToolBarManager;
+#endif
+
+#ifndef QT_NO_PRINTER
+    class QPrinter;
+#endif
 
 /*!
@@ -143,5 +152,5 @@
     void closeEvent(QCloseEvent *ev);
     void dragEnterEvent(QDragEnterEvent *ev);
-    void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL);
+    void drawNode(QPainter &pic, int nstep, bool left = false, TSPSolver::SStep *step = NULL);
     void dropEvent(QDropEvent *ev);
     QByteArray generateImage(const QString &format);
@@ -152,6 +161,6 @@
     void loadToolbarList();
     bool maybeSave();
-    void outputMatrix(QTextCursor &cur, const TMatrix &matrix);
-    void outputMatrix(QTextCursor &cur, const SStep &step);
+    void outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix);
+    void outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step);
 #ifdef Q_OS_SYMBIAN
     void resizeEvent(QResizeEvent *ev);
@@ -166,4 +175,5 @@
 
 #ifdef Q_OS_SYMBIAN
+#include <QMessageBox>
 // A quickly hacked QMessageBox for Symbian that supports three buttons.
 class QSMessageBox: public QMessageBox {
Index: src/pch.h
===================================================================
--- src/pch.h	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/pch.h	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -27,4 +27,19 @@
 
 #ifdef __cplusplus
-	#include "globals.h"
+#   include "globals.h"
+#   include <QtCore>
+#   include <QtGui>
+#   if defined(QT_NO_SVG) && !defined(NOSVG)
+#       define NOSVG
+#   endif
+#   if !defined(NOSVG)
+#       include <QtSvg>
+#   endif // NOSVG
+#   if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+#       include <QtConcurrent>
+#       include <QtPrintSupport>
+#   endif
+#   ifndef HANDHELD
+#       include "qttoolbardialog.h"
+#   endif
 #endif // __cplusplus
Index: src/settingsdialog.cpp
===================================================================
--- src/settingsdialog.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/settingsdialog.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -23,4 +23,23 @@
 
 #include "settingsdialog.h"
+
+#include <QColorDialog>
+#include <QFontDialog>
+#include <QImageWriter>
+#include <QMessageBox>
+#include <QSettings>
+
+#ifdef HANDHELD
+#   include <QScrollArea>
+#endif
+
+#if !defined(QT_NO_STATUSTIP)
+#   include <QStatusTipEvent>
+#endif
+
+#ifndef HANDHELD
+    // Eyecandy
+#   include "qtwin.h"
+#endif // HANDHELD
 
 /*!
Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/tspmodel.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -24,4 +24,13 @@
 #include "tspmodel.h"
 
+#include <QApplication>
+#include <QFile>
+#include <QMessageBox>
+#include <QSettings>
+#include <QtCore/qmath.h>
+
+#include "tspsolver.h"
+#include "os.h"
+
 /*!
  * \brief Class constructor.
@@ -29,8 +38,5 @@
  */
 CTSPModel::CTSPModel(QObject *parent)
-    : QAbstractTableModel(parent), nCities(0)
-{
-    settings = initSettings(this);
-}
+    : QAbstractTableModel(parent), settings(initSettings(this)), nCities(0) {}
 
 /*!
Index: src/tspmodel.h
===================================================================
--- src/tspmodel.h	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/tspmodel.h	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -30,4 +30,8 @@
 
 #include "globals.h"
+
+#include <QAbstractTableModel>
+#include <QDataStream>
+#include <QVector>
 
 /*!
Index: src/tspsolver.cpp
===================================================================
--- src/tspsolver.cpp	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/tspsolver.cpp	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -23,4 +23,10 @@
 
 #include "tspsolver.h"
+
+#include <QCoreApplication>
+
+#ifdef DEBUG
+#   include <QDebug>
+#endif
 
 //! \internal \brief A short for maximum double, used internally in the solution algorithm.
Index: src/tspsolver.h
===================================================================
--- src/tspsolver.h	(revision 7a39458d16b3ef7ee8286944ce93154b57eadfa0)
+++ src/tspsolver.h	(revision 07e43cf61a7b43ecd24519e37f63d745e516f426)
@@ -29,6 +29,10 @@
 #define TSPSOLVER_H
 
-#include <QtCore>
 #include <limits>
+
+#include <QHash>
+#include <QMutex>
+#include <QObject>
+#include <QStringList>
 
 /*!
